package com.blt.car.me;

import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.blt.car.R;
import com.blt.car.base.BaseTitleBarActivity;
import com.blt.car.base.ViewHolder;

import blt.app_core.api.base.CoreEvent;
import blt.app_core.api.base.CoreManager;
import blt.app_core.api.login.LoginApi;
import blt.app_core.utils.CommonPref;
import blt.app_core.utils.PreferencesConstant;

/**
 * Created by xgp on 2017/6/20.
 */

public class ModifyActivity extends BaseTitleBarActivity {
    @Override
    protected int getLayoutId() {
        return R.layout.activity_modify_pwd;
    }

    @Override
    protected void initView(ViewHolder holder) {
        mTitleBar.setTitle("修改密码");
        final EditText newPwd = holder.get(R.id.modify_new_pwd);
        final EditText conPwd = holder.get(R.id.modify_confirm_pwd);
        holder.get(R.id.modify_edit_submit);
        holder.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String phone = CommonPref.getInstance().getString(PreferencesConstant.PHONE, null);
                String newPass = newPwd.getText().toString();
                String conPass = conPwd.getText().toString();
                if (!newPass.equals(conPass) || TextUtils.isEmpty(newPass) || TextUtils.isEmpty(conPass)) {
                    toastShort("密码不同或者密码空");
                    return;
                }
                CoreManager.getCore(LoginApi.class).modifyPwd(phone, newPass);
            }
        }, R.id.modify_edit_submit);
    }

    @CoreEvent(coreClientClass = LoginApi.class)
    public void onModify() {
        toastShort("修改成功");
        finish();
    }

}
